<template>
    <el-card>
        <el-tabs v-model="activeName">
            <el-tab-pane label="积分有效设置" name="basic">
                <el-form ref="scoreBasicInfoForm" :model="info" :rules="rules" label-width="150px" style="margin-top: 10px;">
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="积分有效期：" prop="expireStart">
                                <el-date-picker
                                    v-model="expireDate.date"
                                    type="datetimerange"
                                    value-format="yyyy-MM-dd HH:mm:ss"
                                    range-separator="至"
                                    start-placeholder="开始日期"
                                    end-placeholder="结束日期" @change="expireDateFormat">
                                </el-date-picker>
                                <el-tooltip class="item" effect="dark" content="在此期间用户可有效获得及消费积分，到期后积分将被自动冻结三天后将会被自动清零。" placement="top-end">
                                    <el-button style="margin-left: 10px">告警提示</el-button>
                                </el-tooltip>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24" style="display: none">
                            <el-form-item label="每日登陆获取积分数:">
                                <el-input v-model="info.loginScore" placeholder="请输入每日登陆获取积分数" style="width: 400px;"/>
                            </el-form-item>
                        </el-col>
<!--                        <el-col :span="24">-->
<!--                            <el-form-item label="每日登陆获取积分数:">-->
<!--                                <el-input v-model="info.loginScore" placeholder="请输入每日登陆获取积分数" style="width: 400px;"/>-->
<!--                            </el-form-item>-->
<!--                        </el-col>-->
                    </el-row>
                </el-form>
            </el-tab-pane>
            <el-tab-pane label="用户服务协议" name="userProtocol">
                <el-form ref="userProtocol" :model="notice" label-width="120px" :rules="userProtocolRules">
                    <el-form-item label="协议具体内容:" prop="userProtocol" style="margin-top: 20px;" >
                        <editor v-model="notice.userProtocol" placeholder="用户服务协内容" :min-height="400"/>
                    </el-form-item>
                </el-form>
            </el-tab-pane>
<!--            <el-tab-pane label="隐私政策" name="userPrivacy">-->
<!--                <el-form ref="userPrivacy" :model="notice" label-width="120px" :rules="userPrivacyRules">-->
<!--                    <el-form-item label="政策具体内容:" prop="userPrivacy"  style="margin-top: 20px;">-->
<!--                        <editor v-model="notice.userPrivacy" placeholder="请输入隐私政策内容" :min-height="400"/>-->
<!--                    </el-form-item>-->
<!--                </el-form>-->
<!--            </el-tab-pane>-->
        </el-tabs>
        <el-form label-width="100px">
            <el-form-item style="text-align: center;margin-left:-100px;margin-top:10px;">
                <el-button type="primary" @click="submitForm()">保存设置</el-button>
            </el-form-item>
        </el-form>
    </el-card>
</template>

<script>
import {getConfigValue, updateConfigValue} from "@/api/system/config";
import {getSpecialNotice, updateNotice} from "@/api/system/notice";
export default {
    name: "Score",
    data() {
        return {
            notice:{
                'userPrivacy':'',
                'userProtocol':'',
            },
            realNotice:{},
            // 选中选项卡的 name
            activeName: "basic",
            // 表格的高度
            tableHeight: document.documentElement.scrollHeight - 245 + "px",

            info: {
                'start':'',
                'end':'',
                'loginScore':'',
            },
            config:
                [
                    {
                        'configId':7,
                        'configKey':'scoreExpire',
                        'start':'',
                        'end':''
                    },
                    {
                        'configId':8,
                        'configKey':'loginScore',
                    }
                ]
            ,
            expireDate:{
                date:[],
            },
            userProtocolRules:{
                userProtocol: [
                    {required: true, message: "请输入用户服务协议", trigger: "blur"}
                ]
            },
            userPrivacyRules:{
                userPrivacy: [
                    {required: true, message: "请输入用户隐私政策", trigger: "blur"}
                ]
            },
            rules: {
                start: [
                    {required: true, message: "请输入开始时间", trigger: "blur"}
                ],
                end: [
                    {required: true, message: "请输入结束", trigger: "blur"}
                ],
                loginScore: [
                    {required: true, message: "请输入每日登陆获取积分数", trigger: "blur"}
                ]
            }
        };
    },
    created() {
        this.getConfig();
        this.getNotice();
    },
    methods: {
        getNotice(){
            getSpecialNotice().then(resp=>{
                this.notice = resp.data;
            })
        },
        getConfig() {
            getConfigValue().then(resp=>{
                this.info = resp.data;
                this.expireDate.date.push(this.info.start);
                this.expireDate.date.push(this.info.end);
            })
        },
        expireDateFormat(expire) {
            this.info.start =expire[0].toString();
            this.info.end = expire[1].toString();
        },
        /** 提交按钮 */
        submitForm() {
            if (this.activeName=='basic') {
                this.$refs["scoreBasicInfoForm"].validate(varlidate=>{
                    if (varlidate) {
                        updateConfigValue(this.info)
                        this.$modal.msgSuccess("保存设置成功");
                    }
                })
            }
            //用户服务协议
            else if (this.activeName=='userProtocol'){
                this.notice.noticeId=100;
                this.$refs["userProtocol"].validate(varlidate=>{
                    this.realNotice.noticeId = 100;
                    this.realNotice.noticeTitle = '用户服务协议';
                    this.realNotice.noticeType=3;
                    this.realNotice.noticeContent = this.notice.userProtocol;
                    if (varlidate) {
                        updateNotice(this.realNotice);
                        this.$modal.msgSuccess("保存设置成功");
                    }
                })
            }
            //userPrivacy
            else if (this.activeName=='userPrivacy') {

                this.$refs["userPrivacy"].validate(varlidate=>{
                    this.realNotice.noticeId = 101;
                    this.realNotice.noticeContent = this.notice.userPrivacy;
                    this.realNotice.noticeTitle = '隐私协议';
                    this.realNotice.noticeType=4;
                    if (varlidate) {
                        updateNotice(this.realNotice);
                        this.$modal.msgSuccess("保存设置成功");
                    }
                })
            }
            else {}
        },

    }
};
</script>
